package com.ym.controller.doctor.contacts;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ym.common.constant.Constants;
import com.ym.core.annotation.ApiSign;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.core.shiro.ShiroUtil;
import com.ym.medical.domain.entity.DoctorDetailsEntity;
import com.ym.medical.domain.param.DoctorDetailsParam;
import com.ym.medical.domain.vo.DoctorDetailAllInfoVo;
import com.ym.medical.domain.vo.DoctorLinkVo;
import com.ym.medical.domain.vo.ResultDoctor;
import com.ym.medical.service.IAddressListSV;
import com.ym.medical.service.IDoctorDetailsSV;
import com.ym.medical.service.IResultDoctorSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 通讯录医生相关接口
 *
 * @author: 李涛
 * @version: 2019年05月22日 10:24
 */
@Api(tags = "医生端-通讯录-医生相关")
@RestController
@ApiSign
@RequestMapping(value = "/doctor/contacts/doctor",headers = Constants.Api.VERSION)
@Validated
public class ContactsDoctorController extends BaseController {

	@Autowired
	private IAddressListSV addressListSV;

	@Autowired
	private IDoctorDetailsSV doctorDetailsSV;

	@Autowired
	private IResultDoctorSV resultDoctorSV;

	@Log(dataBase = false, printBody = false)
	@ApiOperation(value = "通讯录医生列表查询")
	@GetMapping("/members")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "keywords", value = "关键词:手机号/姓名", required = false, paramType = "query"),
	})

	public APIResponse<PageInfo<DoctorLinkVo>> members(
			String keywords,
			@RequestParam(defaultValue = "1") int pageNum,
			@RequestParam(defaultValue = "5") int pageSize
	) {
		PageInfo<DoctorLinkVo> data = addressListSV.listDoctor(keywords,ShiroUtil.getLoginId(), pageNum, pageSize);
		return successData(data);
	}

	@Log(dataBase = false, printBody = false)
	@ApiOperation(value = "平台医生列表查询")
	@GetMapping("/platform/members")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "keywords", value = "关键词:手机号/姓名", required = false, paramType = "query"),
	})
	public APIResponse<PageInfo<ResultDoctor>> platformMembers(
			String keywords,
			@RequestParam(defaultValue = "1") int pageNum,
			@RequestParam(defaultValue = "5") int pageSize
	) {
		PageHelper.startPage(pageNum, pageSize);
		List<ResultDoctor> data = doctorDetailsSV.listPagePlatformMembers(keywords, ShiroUtil.getLoginId());
		return successData(new PageInfo<>(data));
	}

	@Log(dataBase = false, printBody = false)
	@ApiOperation(value = "查看医生个人信息")
	@GetMapping("/member/info")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, paramType = "query"),
	})
	public APIResponse<DoctorDetailAllInfoVo> memberInfo(
			@NotNull Long doctorId
	) {
		DoctorDetailAllInfoVo resultDocDetail = resultDoctorSV.selectDoctorDetail(doctorId);
		return successData(resultDocDetail);
	}

	@Log(dataBase = false, printBody = false)
	@ApiOperation(value = "查看医生的/医学教育背景/学术研究成果/诊所介绍/擅长")
	@GetMapping("/member/three/info")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "doctorId", value = "医生ID", required = true, paramType = "query"),
	})
	public APIResponse<DoctorDetailsEntity> memberThreeInfo(
			@NotNull Long doctorId
	) {
		DoctorDetailsEntity doctorDetail = doctorDetailsSV.findByModel(DoctorDetailsParam.builder().id(doctorId).build());
		return successData(doctorDetail);
	}

	@Log(dataBase = false, printBody = false)
	@ApiOperation(value = "新朋友(含好友通知/可能认识的人)")
	@GetMapping("/member/newer")
	public APIResponse memberNew() {
		return success();
	}

	@Log
	@ApiOperation(value = "添加医生为好友,验证")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "content", value = "验证内容", required = false, paramType = "form"),
	})
	@PostMapping(value = "/member/add", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
	public APIResponse memberAdd(
			String content
	) {
		return success();
	}

}
